/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-1-10 下午3:58 Created by dwzhang
 */
package com.jade.modules.region;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;

/**
 * 定义地理位置上的一个地区,包括国家、省/州、县等等。地区的名称
 * 采用因为字母表示.国家为一级地区，国家的名称采用ISO 3166规范.
 * 一个地区的标识采用国家定义的代码。
 *
 * @author sky
 * @version 1.0 13-4-23 上午11:16
 */
@Entity
@Table (name = "MODULE_REGION")
public class Region
        implements Serializable
{
    public static final String TYPE_COUNTRY = "country";
    public static final String TYPE_STATE = "state";
    public static final String TYPE_PROVINCE = "province";
    public static final String TYPE_CITY = "city";
    public static final String TYPE_MUNICIPALITY = "municipality";
    public static final String TYPE_DISTRICT = "district";
    public static final String TYPE_COUNTY = "county";
    public static final String TYPE_TOWN = "town";
    public static final String TYPE_VILLAGE = "village";

    /** 地区标识*/
    @Id
    protected String id;
    /** 上级地区标识 */
    @Column (name = "parent_id", length = 32)
    protected String parentId;
    /** 地区类型包括国家、省、州、自治区、市、县、镇、乡、村等等 */
    @Column (name = "type", length = 16)
    protected String type;
    /** 中文名称 */
    @Column (name = "cn_name", length = 64)
    protected String cnName;
    /** 中文简称 */
    @Column (name = "abbr_cn_name", length = 16)
    protected String abbrCnName;
    /** 英文名称 */
    @Column (name = "en_name", length = 64)
    protected String enName;
    @Column (name = "first_spell", length = 16)
    /** 中文名称简拼 */
    protected String firstSpell;
    @Column (name = "full_spell", length = 64)
    /** 中文名称全称 */
    protected String fullSpell;
    /** 区号/代码。对于国家来说，就是国家代码；对于省来说，就是省代码. */
    @Column (name = "code", length = 32)
    protected String code;
    /** 邮政编码 */
    @Column (name = "zipcode", length = 16)
    protected String zipcode;

    @Transient
    protected List<Region> children;
    @Transient
    protected Region parent;

    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getParentId()
    {
        return parentId;
    }

    public void setParentId(String parentId)
    {
        this.parentId = parentId;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }


    public List<Region> getChildren()
    {
        return children;
    }

    public void setChildren(List<Region> children)
    {
        this.children = children;
    }

    public void addChild(Region region)
    {
        if (children == null) {
            children = new ArrayList<Region>();
        }
        children.add(region);
    }

    public Region getParent()
    {
        return parent;
    }

    public void setParent(Region parent)
    {
        this.parent = parent;
    }

    public String getCode()
    {
        return code;
    }

    public void setCode(String code)
    {
        this.code = code;
    }

    public String getZipcode()
    {
        return zipcode;
    }

    public void setZipcode(String zipcode)
    {
        this.zipcode = zipcode;
    }

    public String getCnName()
    {
        return cnName;
    }

    public void setCnName(String cnName)
    {
        this.cnName = cnName;
    }

    public String getAbbrCnName()
    {
        return abbrCnName;
    }

    public void setAbbrCnName(String abbrCnName)
    {
        this.abbrCnName = abbrCnName;
    }

    public String getEnName()
    {
        return enName;
    }

    public void setEnName(String enName)
    {
        this.enName = enName;
    }

    public String getFirstSpell()
    {
        return firstSpell;
    }

    public void setFirstSpell(String firstSpell)
    {
        this.firstSpell = firstSpell;
    }

    public String getFullSpell()
    {
        return fullSpell;
    }

    public void setFullSpell(String fullSpell)
    {
        this.fullSpell = fullSpell;
    }
}